using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using PickGold.Charting;

namespace PickGold.Charting.Borders3D
{
	internal class EmbossBorder : IBorderType
	{
		internal float[] cornerRadius = new float[] { 15f, 15f, 15f, 15f, 15f, 15f, 15f, 15f };
		public float defaultRadiusSize = 15f;
		public float resolution = 96f;

		public virtual void AdjustAreasPosition(ChartGraphics graph, ref RectangleF areasRect)
		{
			SizeF size = new SizeF(this.defaultRadiusSize / 2f, this.defaultRadiusSize / 2f);
			size = graph.GetRelativeSize(size);
			if (size.Width < 30f)
			{
				areasRect.X += size.Width;
				areasRect.Width -= Math.Min(areasRect.Width, size.Width * 2.5f);
			}
			if (size.Height < 30f)
			{
				areasRect.Y += size.Height;
				areasRect.Height -= Math.Min(areasRect.Height, size.Height * 2.5f);
			}
			if ((areasRect.X + areasRect.Width) > 100f)
			{
				areasRect.X -= 100f - areasRect.Width;
			}
			if ((areasRect.Y + areasRect.Height) > 100f)
			{
				areasRect.Y -= 100f - areasRect.Height;
			}
		}

		public virtual void DrawBorder(ChartGraphics graph, BorderSkin borderSkin, RectangleF rect, Color backColor, ChartHatchStyle backHatchStyle, string backImage, ChartImageWrapMode backImageWrapMode, Color backImageTransparentColor, ChartImageAlignmentStyle backImageAlign, GradientStyle backGradientStyle, Color backSecondaryColor, Color borderColor, int borderWidth, ChartDashStyle borderDashStyle)
		{
			RectangleF ef = graph.Round(rect);
			RectangleF ef2 = ef;
			float num = 0.2f + ((0.4f * ((borderSkin.PageColor.R + borderSkin.PageColor.G) + borderSkin.PageColor.B)) / 765f);
			Color centerColor = Color.FromArgb((int)(borderSkin.PageColor.R * num), (int)(borderSkin.PageColor.G * num), (int)(borderSkin.PageColor.B * num));
			if (borderSkin.PageColor == Color.Transparent)
			{
				centerColor = Color.FromArgb(60, 0, 0, 0);
			}
			num += 0.2f;
			Color color2 = Color.FromArgb((int)(borderSkin.PageColor.R * num), (int)(borderSkin.PageColor.G * num), (int)(borderSkin.PageColor.B * num));
			float num2 = Math.Max(this.defaultRadiusSize, (2f * this.resolution) / 96f);
			num2 = Math.Min(num2, rect.Width / 2f);
			num2 = Math.Min(num2, rect.Height / 2f);
			num2 = (float)Math.Ceiling((double)num2);
			using (Brush brush = new SolidBrush(borderSkin.PageColor))
			{
				graph.FillRectangle(brush, rect);
			}
			ef2 = ef;
			ef2.Width -= num2 * 0.3f;
			ef2.Height -= num2 * 0.3f;
			graph.DrawRoundedRectShadowAbs(ef2, this.cornerRadius, num2 + ((1f * this.resolution) / 96f), color2, borderSkin.PageColor, 1.4f);
			ef2 = ef;
			ef2.X = ef.X + (num2 / 3f);
			ef2.Y = ef.Y + (num2 / 3f);
			ef2.Width -= num2 / 3.5f;
			ef2.Height -= num2 / 3.5f;
			graph.DrawRoundedRectShadowAbs(ef2, this.cornerRadius, num2, centerColor, borderSkin.PageColor, 1.3f);
			ef2 = ef;
			ef2.X = ef.X + ((3f * this.resolution) / 96f);
			ef2.Y = ef.Y + ((3f * this.resolution) / 96f);
			ef2.Width -= num2 * 0.75f;
			ef2.Height -= num2 * 0.75f;
			GraphicsPath path = graph.CreateRoundedRectPath(ef2, this.cornerRadius);
			graph.DrawPathAbs(path, backColor, backHatchStyle, backImage, backImageWrapMode, backImageTransparentColor, backImageAlign, backGradientStyle, backSecondaryColor, borderColor, borderWidth, borderDashStyle, PenAlignment.Inset);
			if (path != null)
			{
				path.Dispose();
			}
			Region region = new Region(graph.CreateRoundedRectPath(new RectangleF(ef2.X - num2, ef2.Y - num2, (ef2.Width + num2) - (num2 * 0.25f), (ef2.Height + num2) - (num2 * 0.25f)), this.cornerRadius));
			region.Complement(graph.CreateRoundedRectPath(ef2, this.cornerRadius));
			graph.Clip = region;
			graph.DrawRoundedRectShadowAbs(ef2, this.cornerRadius, num2, Color.Transparent, Color.FromArgb(0x80, Color.Gray), 0.5f);
			graph.Clip = new Region();
		}

		public virtual RectangleF GetTitlePositionInBorder()
		{
			return RectangleF.Empty;
		}

		public virtual string Name
		{
			get
			{
				return "Emboss";
			}
		}

		public virtual float Resolution
		{
			set
			{
				this.resolution = value;
				float num = (15f * value) / 96f;
				this.defaultRadiusSize = num;
				this.cornerRadius = new float[] { num, num, num, num, num, num, num, num };
			}
		}
	}
}

